package com.hc.sp04.order.service;

import com.hc.sp04.feign.ItemClient;
import com.hc.sp04.feign.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sp01.pojo.Item;
import sp01.pojo.Order;
import sp01.pojo.User;
import sp01.service.OrderService;
import sp01.util.JsonResult;

import java.util.List;

/**
 * TODO 在注释中 标记还没完成的东西
 *
 * @author Z
 * @DATE 2021/8/30 16:14
 * @e-mail ...@qq.com
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private ItemClient itemClient;
    @Autowired
    private UserClient userClient;

    @Override
    public Order getOrder(String orderId) {
       log.info("获取订单，orderId="+orderId);
//       TODO:远程调用商品，获取商品列表
        JsonResult<List<Item>> items = itemClient.getItems(orderId);
//       TODO：远程调用用户，获取用户数据
        JsonResult<User> user = userClient.getUser(8);//获取登录用户id

       Order order = new Order();
       order.setId(orderId);
//       order.setUser(用户);  //通过远程调用用户服务获取用户
        order.setUser(user.getData());  //从Json转成对象...
//       order.setItem(商品);  //通过远程调用商品服务获取商品列表
        order.setItems(items.getData());  //从Json转成对象...
       return order;
    }

    @Override
    public void addOrder(Order order) {
        log.info("添加订单："+order);
//        TODO 远程调用商品，减少商品库存
//        TODO 远程调用用户，增加用户积分
    }
}
